home *** CD-ROM | disk | FTP | other *** search
/ 130 MIDI Tool Box / 130 MIDI Tool Box.iso / mpu401 / setpat.c < prev    next >
C/C++ Source or Header  |  1986-11-02  |  2KB  |  77 lines

  1. /* Copyright (C) 1986 by M. J. Shannon, Jr.
  2. ** Permission to distribute for non-commercial uses granted as long as this
  3. ** notice is retained.  Violators will be prosecuted.
  4. */
  5.  
  6. #include    <stdio.h>
  7. #include    "mpu/mpu.h"
  8.  
  9. void setavoice();
  10.  
  11. unsigned char read_buf[256];    /* a buffer to read into */
  12. unsigned char patch_buf[256];    /* a buffer to read into */
  13.  
  14. int
  15. main(argc, argv, envp)
  16. int argc;
  17. char **argv;
  18. char **envp;
  19. {
  20.     char *vers_string;
  21.  
  22.     /* reset the MPU */
  23.     mpu_reset();
  24.     /* get the firmware version/revision */
  25.     vers_string = mpu_id();
  26.     /* show it to the user */
  27.     printf("MPU: %s\n", vers_string);
  28.     /* enable various options */
  29.     mpu_put(SWE_HEXCL);
  30.     mpu_put(SWE_DATAINSTOP);
  31.     mpu_put(SWE_TIME);
  32.     /* and load the patch */
  33.     setavoice();
  34.     /* return success to DOS */
  35.     return (0);
  36. }
  37.  
  38. void
  39. setavoice()
  40. {
  41.     int length;
  42.     int i;
  43.     FILE *fp;
  44.     char s[256];
  45.  
  46. getfile:;
  47.     /* ask for a filename to read the patch from */
  48.     printf("File name:");
  49.     gets(s);
  50.     /* to get out, just hit CR */
  51.     if (s[0] == '\0')
  52.         exit(0);
  53.     /* create the file for binary i/o */
  54.     fp = fopen(s, "rb");
  55.     /* complain if we couldn't */
  56.     if (!fp)
  57.     {
  58.         printf("Couldn't open <%s>!\n", s);
  59.         goto getfile;
  60.     }
  61.     /* read it in */
  62.     fread(patch_buf, 102, 1, fp);
  63.     /* close the file */
  64.     fclose(fp);
  65.     printf("Loading...");
  66.     mpu_sexcl(patch_buf);
  67.     printf("\n");
  68.     /* read until we get something */
  69.     while ((length = mpu_read(&read_buf[0])) == 0)
  70.         /* tell user we didn't get anything */
  71.         printf("Waiting...\n");
  72.     printf("Reply was %d bytes:\n", length);
  73.     for (i = 0; i < length; ++i)
  74.         printf("%.2x ", read_buf[i]);
  75.     printf("\n");
  76. }
  77.